﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MudEngine
{
	public class MudContext
	{
		/// <summary>
		/// 
		/// </summary>
		public static string TMP_DIR { get { return GetProperty("TMP"); } }
		/// <summary>
		/// 
		/// </summary>
		public static string BIN_DIR { get { return GetProperty("BIN"); } }
		/// <summary>
		/// 
		/// </summary>
		public static string CACHE_DIR { get { return GetProperty("CACHE"); } }
		/// <summary>
		/// 
		/// </summary>
		public static string LIB_DIR { get { return GetProperty("LIB"); } }
		/// <summary>
		/// 
		/// </summary>
		public static string DRIVER { get { return GetProperty("DRIVER"); } }
        /// <summary>
        /// 
        /// </summary>
        public static string KFUN { get { return GetProperty("KFUN"); } }
        /// <summary>
		/// 
		/// </summary>
		public static byte[] HASH_SALT { get { return Encoding.Default.GetBytes(GetProperty("HASH_SALT")); } }
		/// <summary>
		/// 
		/// </summary>
		public static string HASH_ALG { get { return GetProperty("HASH_ALG"); } }
		/// <summary>
		/// 
		/// </summary>
		public static int OBJ_INIT_LIFESPAN { get { return int.Parse(GetProperty("OBJ_INIT_LIFESPAN")); } }
		/// <summary>
		/// 
		/// </summary>
		public static int OBJ_RENEW { get { return int.Parse(GetProperty("OBJ_RENEW")); } }
		/// <summary>
		/// 
		/// </summary>
		public static int OBJ_RENEW_TIMEOUT { get { return int.Parse(GetProperty("OBJ_RENEW_TIMEOUT")); } }
        /// <summary>
        /// 
        /// </summary>
        public static int INT_STACK_SIZE { get { return int.Parse(GetProperty("INT_STACK_SIZE")); } }
        /// <summary>
        /// 
        /// </summary>
        public static int INT_CONTROLSTACK_SIZE { get { return int.Parse(GetProperty("INT_CONTROLSTACK_SIZE")); } }
        /// <summary>
        /// 
        /// </summary>
        public static int INT_MAX_EXEC_TIME { get { return int.Parse(GetProperty("INT_MAX_EXEC_TIME")); } }
        /// <summary>
		/// 
		/// </summary>
		/// <param name="property"></param>
		/// <returns></returns>
		public static string GetProperty(string property)
		{
			return ConfigurationManager.AppSettings[property];
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="property"></param>
		/// <param name="defaultValue"></param>
		/// <returns></returns>
		public static int GetProperty(string property, int defaultValue)
		{
			try
			{
				return int.Parse(GetProperty(property));
			}
			catch (FormatException fe)
			{
				Log.Info(typeof(MudContext), "Property '" + property + "' is not a number: ", fe);

				return defaultValue;
			}
		}

	}
}
